package com.it.service;

import com.it.mapper.LinkFoodCartMapper;
import com.it.pojo.LinkFoodCart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 菜品/套餐和购物车关联关系
 */
@Service
@Transactional
public class LinkFoodCartServiceImpl implements LinkFoodCartService {

    @Autowired
    private LinkFoodCartMapper linkFoodCartMapper;

    /**
     * 1.1、根据cartId查（查某客户的所有关联关系）
     */
    public LinkFoodCart findById(String id){
        LinkFoodCart cart = linkFoodCartMapper.findById(id);
        return cart;
    }

    /**
     * 1.2、根据cartId查（查某客户的所有关联关系）
     */
    public List<LinkFoodCart> findByCartId(String cartId){
        List<LinkFoodCart> list = linkFoodCartMapper.findByCartId(cartId);
        return list;
    }

    /**
     * 1.3、根据foodId查（查某菜品的所有关联关系）
     */
    public List<LinkFoodCart> findByFoodId(String foodId){
        List<LinkFoodCart> list = linkFoodCartMapper.findByFoodId(foodId);
        return list;
    }

    /**
     * 1.4、根据cartId和foodId查（查某菜品的所有关联关系）
     */
    public List<LinkFoodCart> findByCartIdAndFoodId(String cartId, String foodId){
        List<LinkFoodCart> list = linkFoodCartMapper.findByCartIdAndFoodId(cartId, foodId);
        return list;
    }

    /**
     * 2、新增一条关联关系
     */
    public int addOne(LinkFoodCart link){
        int i = linkFoodCartMapper.addLinkFoodCart(link);
        return i;
    }

    /**
     * 3、修改一条关联关系
     */
    public int updateOne(LinkFoodCart link){
        int i = linkFoodCartMapper.updateById(link);
        return i;
    }

    /**
     * 4、删除一条关联关系
     */
    public int deleteOne(String linkId){
        int i = linkFoodCartMapper.deleteById(linkId);
        return i;
    }

}
